package ch.selise.exercise.pattern.notepad.command.impl;

import java.util.Scanner;

import ch.selise.exercise.pattern.notepad.command.BaseCommand;
import ch.selise.exercise.pattern.notepad.storage.AppStorageSingleton;

public class EditCommand extends BaseCommand // implements IUndoableCommand
{

	String previousText;

	public EditCommand(String text, int index) {
		super.setText(text);
		super.setIndex(index);
	}

	public EditCommand(Scanner in) {
		String text = in.nextLine();
		int index = Integer.parseInt(in.nextLine());
		super.setText(text);
		super.setIndex(index);
	}

	@Override
	public void execute() {
		previousText = AppStorageSingleton.getInstance().getText()
				.get(super.getIndex());
		AppStorageSingleton.getInstance().getText()
				.set(super.getIndex(), super.getText());

		//AppStorageSingleton.getInstance().addCommand(this);
	}

	@Override
	public void undoCommand() {
		super.setText(AppStorageSingleton.getInstance().getText()
				.get(super.getIndex()));
		AppStorageSingleton.getInstance().getText()
				.set(super.getIndex(), previousText);

	}

}
